package com.jingzhi.count.controller;

import com.jingzhi.count.entity.MyResponse;
import com.jingzhi.count.entity.Product;
import com.jingzhi.count.entity.ProductLine;
import com.jingzhi.count.mapper.ProductLineMapper;
import com.jingzhi.count.utils.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.UUID;

/**
 * 作者： 张恒同
 * 时间： 2018/3/29   13:50
 * 描述： 生产线
 */
@RestController
public class ProductLineController extends BaseController{

    @Autowired
    ProductLineMapper   mapper;

    @RequestMapping("/addProductLine.do")
    public ResponseEntity<MyResponse> addProductLine(@RequestParam(value = "name", required = true) String name){
        MyResponse response = new MyResponse();

        List<ProductLine> lines = mapper.selectAll();
        for (ProductLine line : lines){
            if (line.getProdName().equals(name)){
                response.setRc(MyResponse.ERROR);
                response.setDes("生产线已存在");
                return new ResponseEntity<MyResponse>(response, HttpStatus.OK);
            }
        }

        ProductLine line = new ProductLine();
        line.setProdName(name);
        line.setCreateTime(String.valueOf(TimeUtils.getTimeStamp()));
        line.setIsUsed(1);
        mapper.insert(line);

        response.setRc(MyResponse.SUCCESS);
        response.setDes("生产线添加成功");

        return new ResponseEntity<MyResponse>(response, HttpStatus.OK);
    }

}
